//
//  WBTextField.m
//  VoiceLive
//
//  Created by 凸阿滨 on 2017/10/20.
//  Copyright © 2017年 WB. All rights reserved.
//

#import "WBTextField.h"
#import "UIView+Frame.h"
#define COLOR_WITH_HEX(hexValue) [UIColor colorWithRed:((float)((hexValue & 0xFF0000) >> 16)) / 255.0 green:((float)((hexValue & 0xFF00) >> 8)) / 255.0 blue:((float)(hexValue & 0xFF)) / 255.0 alpha:1.0f]
@implementation WBTextField
//通过代码创建
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setUpUI];
    }
    return self;
}
//通过xib创建
-(void)awakeFromNib
{
    [super awakeFromNib];
    [self setUpUI];
}

- (void)setUpUI
{
    self.returnKeyType = UIReturnKeyNext;
    
    //    设置border
        self.layer.masksToBounds = YES;
        self.layer.cornerRadius = 23;
        self.layer.borderColor = [UIColor whiteColor].CGColor;
        self.layer.borderWidth = 1;
    //字体大小
    self.font = [UIFont systemFontOfSize:18];
    self.tintColor = [UIColor whiteColor];  //设置光标颜色
    
    //修改占位符文字颜色
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSForegroundColorAttributeName] = [UIColor whiteColor];
    self.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"帐号" attributes:attrs];
  
    // 不成为第一响应者
    [self resignFirstResponder];
}







-(void)drawPlaceholderInRect:(CGRect)rect{
    CGFloat y;
    if(iOS11_1Later){
        y = 0;
    }else{
        y = 10;
    }
    
    
    [self.placeholder drawInRect:CGRectMake(20, y, rect.size.width, 50) withAttributes:@{
                                                                                        NSForegroundColorAttributeName : COLOR_WITH_HEX(0x5c6672),
                                                                                        NSFontAttributeName : self.font}];
    
   



}


-(CGRect)editingRectForBounds:(CGRect)bounds
{
    CGRect inset = CGRectMake(bounds.origin.x+10, bounds.origin.y, bounds.size.width, bounds.size.height);//更好理解些
    return inset;
}

//控制显示文本的位置
-(CGRect)textRectForBounds:(CGRect)bounds
{
    
    CGRect inset = CGRectMake(bounds.origin.x+10, bounds.origin.y , bounds.size.width , bounds.size.height);
    return inset;
}










@end
